package com.myaxuan.controller.permissions;

import com.myaxuan.common.CommonResponse;
import com.myaxuan.common.ResponseUtil;
import com.myaxuan.entity.permissions.Role;
import com.myaxuan.service.permissions.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by pc255 on 2018/4/25.
 */

@Controller
@RequestMapping("role")
public class RoleController {

	@Autowired
	private RoleService roleService;

	@RequestMapping("index")
	public String index(){
		return "permissions/role";
	}

	@RequestMapping("delete")
	@ResponseBody
	public int deleteByPrimaryKey(String id){
		return roleService.deleteByPrimaryKey(id);
	}


	@RequestMapping("add")
	@ResponseBody
	public int insertSelective(Role role){
		return roleService.insertSelective(role);
	}

	@RequestMapping("modify")
	@ResponseBody
	public int updateByPrimaryKeySelective(Role menu){
		return roleService.updateByPrimaryKeySelective(menu);
	}


	@RequestMapping("find")
	@ResponseBody
	public CommonResponse selectByPrimaryKey(@RequestParam(value="id" ,defaultValue = "",required = false) String menuId,
	                                         @RequestParam(value="page" ,defaultValue = "",required = false) Integer page,
	                                         @RequestParam(value="limit" ,defaultValue = "",required = false)Integer limit){
		return ResponseUtil.generateResponse(roleService.selectByPrimaryKey(menuId),1);
	}

	@RequestMapping("page")
	@ResponseBody
	public CommonResponse findAll(@RequestParam(value="page" ,defaultValue = "",required = false) Integer page,
	                              @RequestParam(value="limit" ,defaultValue = "",required = false)Integer limit){
		return ResponseUtil.generateResponse(roleService.findAll(page,limit),200);
	}

}
